package com.czh.springboot04.MyController;


import com.czh.springboot04.entity.ConsultConti;
import com.czh.springboot04.service.ConsultContiService;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultconti")
@CrossOrigin
public class ConsultContiController {
    @Autowired
    private ConsultContiService consultcontiService;

    @PostMapping("/insert")
    public R insert(@RequestBody ConsultConti consultconti){
        int i = consultcontiService.insert(consultconti);
        if (i!=0){
            return R.ok("添加成功");
        }else {
            return R.error("添加失败");
        }
    }
    @PutMapping("/update")
    public R update(@RequestBody ConsultConti consultconti){
        int i = consultcontiService.update(consultconti);
        if (i!=0){
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }
    }
    @DeleteMapping("/delete")
    public R delete(int id){
        int i = consultcontiService.delete(id);
        if (i!=0){
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }
    }
    @GetMapping("/selectByPage")
    public R selectByPage(int pageNum,int pageSize){
        PageInfo<ConsultConti> pageInfo = consultcontiService.selectByPage(pageNum, pageSize);
        return R.ok(pageInfo);
    }
    @GetMapping("/selectById")
    public R selectById(int id){
        ConsultConti consultconti = consultcontiService.selectById(id);
        return R.ok(consultconti);
    }

    @GetMapping("/selectAll")
    public R selectAll(){
        List<ConsultConti> consultContis = consultcontiService.selectAll();
        return R.ok(consultContis);
    }
    @GetMapping("/selectByConId/{conId}")
    public R selectByConId(@PathVariable("conId") int conId){
        ConsultConti consultconti = consultcontiService.selectByConId(conId);
        return R.ok(consultconti);
    }
}
